﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.IO;
using Clipping.Utils;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;

namespace ClippingEditor
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        Log4cb.ILog4cbHelper logHelper = new Log4cb.Log4cbHelper("ClippingEditor");
        public static bool StartAlone = false;
        protected override void OnStartup(StartupEventArgs e)
        {
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
            StartAlone = true;
   
            base.OnStartup(e);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
          
        }

        void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            logHelper.LogErrMsg(e.ExceptionObject as Exception, "CurrentDomain_UnhandledException");
            if (e.IsTerminating)
            {
                logHelper.LogInfoMsg("进程崩溃！");

                //Dump
                if (!System.Diagnostics.Debugger.IsAttached)
                {
                    logHelper.LogInfoMsg("正在创建DUMP......");

                    MiniDump.Dump(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Dumps", "ClappingEditor_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".dmp"));

                    logHelper.LogInfoMsg("DUMP完毕！");
                }
                Environment.Exit(-1);
            }
        }


      
        protected override void OnExit(ExitEventArgs e)
        {
            Log4cb.Log4cbHelper.UnInitialize();
            Environment.Exit(0);
            base.OnExit(e);
        }
    }
}
